﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Service;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.CommonComponent
{
    public class ComputeComponentScaleViewModel : BindableBase
    {
        #region 打开计算器
        /// <summary>
        /// 对话服务
        /// </summary>
        private readonly DialogHostService DialogHostService;

        /// <summary>
        /// 打开计算器命令
        /// </summary>
        public DelegateCommand<string> CalculatorCmm { get; set; }

        /// <summary>
        /// 打开计算器方法
        /// </summary>
        /// <param name="unitValue">单位</param>
        private async void CalculatorFun(string unitValue)
        {
            DialogParameters paras = new DialogParameters();
            paras.Add("str", unitValue);
            paras.Add("ComputeValue", ComputeValue);
            var result = await DialogHostService.ShowDialog("CalculatorUC", paras);

            if (result.Result == ButtonResult.OK)
            {
                if (result.Parameters.ContainsKey("CurrentCalculatorValue"))
                {
                    bool paresResult = float.TryParse(result.Parameters.GetValue<string>("CurrentCalculatorValue"), out float floatNumber);

                    if (paresResult)
                    {
                        ComputeValue = floatNumber;
                    }
                }
            }
        }
        #endregion

        /// <summary>
        /// 构造器
        /// </summary>
        public ComputeComponentScaleViewModel(DialogHostService _DialogHostService)
        {
            CalculatorCmm = new DelegateCommand<string>(CalculatorFun);

            DialogHostService = _DialogHostService;

            // 绑定缩小和放大
            ZoomOutCmm = new DelegateCommand(ZoomOutFun);
            ZoomInCmm = new DelegateCommand(ZoomInFun);
        }


        #region 计算值
        /// <summary>
        /// 计算值
        /// </summary>
        private float _ComputeValue;

        /// <summary>
        /// 计算值
        /// </summary>
        public float ComputeValue
        {
            get { return _ComputeValue; }
            set
            {
                _ComputeValue = value;
                RaisePropertyChanged();
            }
        }

        #endregion

        #region 是否使用父容器
        /// <summary>
        /// 是否使用父容器
        /// </summary>
        private bool _UseParentValue;

        /// <summary>
        /// 是否使用父容器
        /// </summary>
        public bool UseParentValue
        {
            get { return _UseParentValue; }
            set
            {
                _UseParentValue = value;
                RaisePropertyChanged();
            }
        }
        #endregion

        #region 父传值
        /// <summary>
        /// 父传值
        /// </summary>
        private string _ParentValue;

        /// <summary>
        /// 父传值
        /// </summary>
        public string ParentValue
        {
            get { return _ParentValue; }
            set
            {
                _ParentValue = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 缩小
        /// <summary>
        /// 缩小命令
        /// </summary>
        public DelegateCommand ZoomOutCmm { get; set; }

        /// <summary>
        /// 缩小方法
        /// </summary>
        private void ZoomOutFun()
        {
            ComputeValue /= 2;
        }
        #endregion


        #region 放大
        /// <summary>
        /// 放大命令
        /// </summary>
        public DelegateCommand ZoomInCmm { get; set; }

        /// <summary>
        /// 放大方法
        /// </summary>
        private void ZoomInFun()
        {
            ComputeValue *= 2;
        }
        #endregion

    }
}
